home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / VB98 / WIZARDS / CLSSBLD.DLL / 1033 / TEXT / STDINFO
Encoding:
Text File  |  1998-06-18  |  3.6 KB  |  132 lines

  1. *ERRTEXT
  2. ' Define your custom errors here.  Be sure to use numbers
  3. ' greater than 512, to avoid conflicts with OLE error numbers.
  4. Public Const MyObjectError1 = 1000
  5. Public Const MyObjectError2 = 1010
  6. Public Const MyObjectErrorN = 1234
  7. Public Const MyUnhandledError = 9999
  8.  
  9.  
  10. Private Function GetErrorTextFromResource(ErrorNum As Long) _ 
  11.      As String
  12.    Dim strMsg As String
  13.    
  14.    ' this function will retrieve an error description from a resource
  15.    ' file (.RES).  The ErrorNum is the index of the string
  16.    ' in the resource file.  Called by RaiseError
  17.  
  18.    On Error GoTo GetErrorTextFromResourceError
  19.    
  20.    ' get the string from a resource file
  21.    GetErrorTextFromResource = LoadResString(ErrorNum)
  22.    
  23.    Exit Function
  24.    
  25. GetErrorTextFromResourceError:
  26.    
  27.    If Err.Number <> 0 Then
  28.       GetErrorTextFromResource = "An unknown error has occurred!"
  29.    End If
  30.    
  31. End Function
  32.  
  33. Public Sub RaiseError(ErrorNumber As Long, Source As String)
  34.    Dim strErrorText As String
  35.  
  36.    'there are a number of methods for retrieving the error
  37.    'message.  The following method uses a resource file to
  38.    'retrieve strings indexed by the error number you are
  39.    'raising.
  40.    strErrorText = GetErrorTextFromResource(ErrorNumber)
  41.  
  42.    'raise an error back to the client
  43.    Err.Raise vbObjectError + ErrorNumber, Source, strErrorText
  44.  
  45. End Sub
  46. *END
  47.  
  48. *CLASSID
  49. Function GetNextClassDebugID() As Long
  50.   'class ID generator
  51.   Static lClassDebugID As Long
  52.   lClassDebugID = lClassDebugID + 1
  53.   GetNextClassDebugID = lClassDebugID
  54. End Function
  55. *END
  56.  
  57. *INITTERM
  58. 'set this to 0 to disable debug code in this class
  59. #Const DebugMode = 1
  60.  
  61. #If DebugMode Then
  62.   'local variable to hold the serialized class ID that was created in Class_Initialize
  63.   Private mlClassDebugID As Long
  64. #End If
  65.  
  66. Private Sub Class_Initialize()
  67.   #If DebugMode Then
  68.     'get the next available class ID, and print out
  69.     'that the class was created successfully
  70.     mlClassDebugID = GetNextClassDebugID()
  71.     Debug.Print "'" & TypeName(Me) & "' instance " & mlClassDebugID & " created"
  72.   #End If
  73. End Sub
  74.  
  75. Private Sub Class_Terminate()
  76.   'the class is being destroyed
  77.   #If DebugMode Then
  78.     Debug.Print "'" & TypeName(Me) & "' instance " & CStr(mlClassDebugID) & " is terminating"
  79.   #End If
  80. End Sub
  81.  
  82. #If DebugMode Then
  83.   Public Property Get ClassDebugID()
  84.     'if we are in debug mode, surface this property that consumers can query 
  85.     ClassDebugID = mlClassDebugID
  86.   End Property
  87. #End If
  88. *END
  89.  
  90. *COLLMETH
  91. 'local variable to hold collection
  92. Private mCol As Collection
  93.  
  94. Public Property Get Count() As Long
  95.   'used when retrieving the number of elements in the 
  96.   'collection. Syntax: Debug.Print x.Count
  97.   Count = mCol.Count
  98. End Property
  99.  
  100. Public Sub Remove(vntIndexKey As Variant)
  101.   'used when removing an element from the collection
  102.   'vntIndexKey contains either the Index or Key, which is why
  103.   'it is declared as a Variant
  104.   'Syntax: x.Remove(xyz)
  105.  
  106.   mCol.Remove vntIndexKey
  107. End Sub
  108.  
  109. Public Property Get NewEnum() As IUnknown
  110.   'this property allows you to enumerate
  111.   'this collection with the For...Each syntax
  112.   Set NewEnum = mCol.[_NewEnum]
  113. End Property
  114.  
  115. Private Sub Class_Initialize()
  116.   'creates the collection when this class is created 
  117.   Set mCol = New Collection
  118. End Sub
  119.  
  120. Private Sub Class_Terminate()
  121.   'destroys collection when this class is terminated
  122.   Set mCol = Nothing
  123. End Sub
  124. *END
  125.  
  126. *COLLITEMMETH
  127.   'used when referencing an element in the collection
  128.   'vntIndexKey contains either the Index or Key to the collection,
  129.   'this is why it is declared as a Variant
  130.   'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  131. *END